package com.meilai.project.mapper.business.sale;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.meilai.project.entity.business.sale.BillSaleProxyMediaDetail;
import com.meilai.project.vo.business.sale.BillSaleProxyMediaDetailVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface BillSaleProxyMediaDetailMapper extends BaseMapper<BillSaleProxyMediaDetail> {
    @Delete("DELETE FROM bill_sale_proxy_media_detail WHERE bill_sale_id = #{billSaleId}")
    int deleteByBillSaleId(Long billSaleId);

    @Select("SELECT * FROM bill_sale_proxy_media_detail WHERE bill_sale_id = #{billSaleId} ORDER BY id ASC ")
    List<BillSaleProxyMediaDetailVO> selectByBillSaleId(@Param("billSaleId") Long billSaleId);

    @Select("SELECT SUM(amount) FROM bill_sale_proxy_media_detail WHERE contract_id = #{contractId}")
    BigDecimal getTotalExecutedAmount(@Param("contractId") Long contractId);

}
